/**
 * FileName: OAuthHelper Author:   zeroleavebaoyang Date:     2018/9/4 11:25 Description:
 */
package com.shiro.sso.demo.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shiro.sso.demo.App;
import com.shiro.sso.demo.oauth2.OAuthInfo;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;


@Slf4j
public class OAuthHelper {

    private static JSONObject oauthInfos = null;

    static {
        try {
            InputStream in = App.class.getResourceAsStream("/platform.json");
            String result = IOUtils.toString(in, "UTF-8");
            oauthInfos = JSONObject.parseObject(result);
        } catch (IOException e) {
            log.error("platform.json is not exsit. {}", e);
            e.printStackTrace();
        }
    }

    public static OAuthInfo getOauthInfo(Platform platform) {
        if (oauthInfos != null) {
            JSONObject jsonObject = oauthInfos.getJSONObject(platform.toString());
            if (jsonObject != null) {
                return JSON.parseObject(jsonObject.toJSONString(), OAuthInfo.class);
            }
        }
        return null;
    }


}
